import axios from 'axios'

export default {
   /**
   * post 请求
   *
   * @param url 接口路由
   * @param data 接口参数 对象
   * @param auth 是否需要带登录信息
   * @returns {AxiosPromise<any>}
   */
    post(url, data = {}, auth = false, hideLoading = false) {
        if (auth) {
            return new Promise((resolve, reject) => {
                axios.post(url, data, {hideLoading}).then(res => {
                    resolve(res.data)
                }).catch(err => {
                    reject(err.data)
                })
            })
        } else {
            return new Promise((resolve, reject) => {
                axios.post(url, data, {hideLoading}).then(res => {
                  resolve(res.data)
                }).catch(err => {
                  reject(err.data)
                })
            })
        }
    },
    get(url, params = {}) {
        return new Promise((resolve, reject) => {
            axios.get(url, { params }).then(res => {
                resolve(res.data)
            }).catch(err => {
                reject(err.data)
            })
        })
    }
}